package main

import (
	"net/http"

	example "git.oschina.net/wkc/master-key-go/proto/example"
	"git.oschina.net/wkc/master-key-go/web/master-key-go-web/handler"
	"github.com/emicklei/go-restful"
	"github.com/micro/go-micro/client"
	"github.com/micro/go-web"
)

func main() {
	service := web.NewService(web.Name(handler.NAME))

	wc := restful.NewContainer()

	v1 := new(restful.WebService).Path("/v1").Consumes(restful.MIME_JSON).Produces(restful.MIME_JSON)
	v1.Route(v1.GET("/version").To(handler.Version))
	v1.Route(v1.POST("/send").To(handler.Send))
	v1.Route(v1.GET("/qrcode").To(handler.QrCode))
	wc.Add(v1)

	wc.Handle("/v1/listen", http.HandlerFunc(handler.Listen))
	wc.Handle("/", http.FileServer(http.Dir("static")))

	service.Handle("/", wc)
	service.Init()

	handler.Client = example.NewKeyMqClient("go.micro.api.master-key-go", client.DefaultClient)
	service.Run()
}
